home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / c / rle16_sc.zip / UNRLE16.C < prev    next >
Text File  |  1993-05-10  |  2KB  |  95 lines

  1. /* Run Length Decoder program
  2.  * decodes system.rle file that uses 16 bit headers.
  3.  *
  4.  * written 1991 by Shaun Case in Borland C++ 2.0
  5.  * This program and its source code are public domain.
  6.  *
  7.  * You can't afford not to make the left decision.
  8.  */
  9.  
  10.  
  11. #include <stdio.h>
  12. #include <string.h>
  13. #include "rle16.h"
  14.  
  15. int main(int argc, char **argv)
  16. {
  17.     register int byte;
  18.     register unsigned short i;
  19.     register unsigned short length;
  20.     int packet_hdr;
  21.     
  22.     FILE *infile, *outfile;
  23.  
  24.     char orig_filename[14]; /* original filename */
  25.     char *infile_name;
  26.     char scratch_space[134];
  27.  
  28.     if (argc != 2)
  29.     {
  30.         puts("Usege: unrle16 filename");
  31.         return 1;
  32.     }
  33.     puts("unlre16   by Shaun Case 1991  public domain");
  34.  
  35.     infile_name = argv[1];
  36.  
  37.     if ((infile=fopen(infile_name, "rb")) == NULL)
  38.     {
  39.         strcpy(scratch_space, "Unable to open ");
  40.         strcat(scratch_space, infile_name);
  41.         puts(scratch_space);
  42.         return 1;
  43.     }
  44.  
  45.     for (i = 0; i < 13; i++)   /* get original filename */
  46.         if ((orig_filename[i] = fgetc(infile)) == EOF)
  47.         {
  48.             puts("Error reading original filename from input file.");
  49.             return 1;
  50.         }
  51.  
  52.     if ((outfile=fopen(orig_filename, "wb")) == NULL)
  53.     {
  54.         strcpy(scratch_space, "Unable to open ");
  55.         strcat(scratch_space, orig_filename);
  56.         puts(scratch_space);
  57.         return 1;
  58.     }
  59.  
  60.  
  61.     while (!feof(infile))
  62.     {
  63.         packet_hdr = fgetc(infile);         /* get lo byte   */
  64.  
  65.         if (feof(infile))
  66.             continue;
  67.  
  68.         packet_hdr |= (((short)fgetc(infile)) << 8) ;  /* get high byte */
  69.  
  70.         if (feof(infile))
  71.             continue;
  72.  
  73.  
  74.         length = MAX_LEN & packet_hdr;
  75.  
  76.         if (packet_hdr & RUN)  /* if it's a run... */
  77.         {
  78.             byte = fgetc(infile);
  79.  
  80.             for (i = 0; i < length; i++)
  81.                 fputc(byte, outfile);
  82.         }
  83.  
  84.         else /* it's a sequence */
  85.  
  86.             for (i = 0; i < length; i++)
  87.                 fputc(fgetc(infile), outfile);
  88.  
  89.     }
  90.     fclose(infile);
  91.     fclose(outfile);
  92.     return 0;
  93. }
  94.  
  95.